<!DOCTYPE HTML>
<html lang="en" >
    
    <head>
        
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>时间相关模块 | MXY 1.0版Python整理</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.6.7">
        
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="../../gitbook/style.css">
    
        
        <link rel="stylesheet" href="../../gitbook/plugins/gitbook-plugin-highlight/website.css">
        
    
        
        <link rel="stylesheet" href="../../gitbook/plugins/gitbook-plugin-search/search.css">
        
    
        
        <link rel="stylesheet" href="../../gitbook/plugins/gitbook-plugin-fontsettings/website.css">
        
    
    

        
    
    
    <link rel="next" href="../../home/8.面向对象/1.类和对象-上.html" />
    
    
    <link rel="prev" href="../../home/7.常用模块/6.shutil模块.html" />
    

        
    </head>
    <body>
        
        
    <div class="book"
        data-level="7.7"
        data-chapter-title="时间相关模块"
        data-filepath="home/7.常用模块/7.时间相关模块.md"
        data-basepath="../.."
        data-revision="Mon Oct 22 2018 08:32:35 GMT+0800 (中国标准时间)"
        data-innerlanguage="">
    

<div class="book-summary">
    <nav role="navigation">
        <ul class="summary">
            
            
            
            

            

            
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../../index.html">
                
                        <i class="fa fa-check"></i>
                        
                        MXY整理版Python基础
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" >
            
            <span><b>1.</b> Python的安装和简介</span>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1" data-path="home/1.Python的安装和简介/1.python基础知识.html">
            
                
                    <a href="../../home/1.Python的安装和简介/1.python基础知识.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.1.</b>
                        
                        Python的基础知识
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="home/1.Python的安装和简介/2.python的安装及版本检测.html">
            
                
                    <a href="../../home/1.Python的安装和简介/2.python的安装及版本检测.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.</b>
                        
                        Python安装及版本检测
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="home/1.Python的安装和简介/3.第一个python程序.html">
            
                
                    <a href="../../home/1.Python的安装和简介/3.第一个python程序.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.3.</b>
                        
                        第一个Python程序
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2" >
            
            <span><b>2.</b> Python的基本语法</span>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1" data-path="home/2.Python的基本语法/1.注释及语句分类.html">
            
                
                    <a href="../../home/2.Python的基本语法/1.注释及语句分类.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.1.</b>
                        
                        注释及语句分类
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="home/2.Python的基本语法/2.命名方式和关键字.html">
            
                
                    <a href="../../home/2.Python的基本语法/2.命名方式和关键字.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.</b>
                        
                        命名方式和关键字
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3" >
            
            <span><b>3.</b> Python的变量及数据类型</span>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1" data-path="home/3.变量和数据类型/1.变量.html">
            
                
                    <a href="../../home/3.变量和数据类型/1.变量.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.1.</b>
                        
                        变量
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="home/3.变量和数据类型/2.数据类型.html">
            
                
                    <a href="../../home/3.变量和数据类型/2.数据类型.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.2.</b>
                        
                        数据类型
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="home/3.变量和数据类型/3.数据类型转换.html">
            
                
                    <a href="../../home/3.变量和数据类型/3.数据类型转换.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.</b>
                        
                        数据类型转换
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="home/3.变量和数据类型/4.运算和运算符.html">
            
                
                    <a href="../../home/3.变量和数据类型/4.运算和运算符.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.4.</b>
                        
                        数据类型转换
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4" >
            
            <span><b>4.</b> Python的流程控制</span>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1" data-path="home/4.流程控制/1.顺序结构和分支结构.html">
            
                
                    <a href="../../home/4.流程控制/1.顺序结构和分支结构.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.1.</b>
                        
                        顺序结构和分支结构
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="home/4.流程控制/2.循环结构.html">
            
                
                    <a href="../../home/4.流程控制/2.循环结构.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.2.</b>
                        
                        循环结构
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5" >
            
            <span><b>5.</b> 函数及作用域</span>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1" data-path="home/5.函数及作用域/1.函数.html">
            
                
                    <a href="../../home/5.函数及作用域/1.函数.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.1.</b>
                        
                        函数
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="home/5.函数及作用域/2.函数文档.html">
            
                
                    <a href="../../home/5.函数及作用域/2.函数文档.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.2.</b>
                        
                        函数文档
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.3" data-path="home/5.函数及作用域/3.变量的作用域.html">
            
                
                    <a href="../../home/5.函数及作用域/3.变量的作用域.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.3.</b>
                        
                        变量的作用域
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.4" data-path="home/5.函数及作用域/4.内部函数和闭包操作.html">
            
                
                    <a href="../../home/5.函数及作用域/4.内部函数和闭包操作.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.4.</b>
                        
                        内部函数和闭包操作
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.5" data-path="home/5.函数及作用域/5.lambda表达式.html">
            
                
                    <a href="../../home/5.函数及作用域/5.lambda表达式.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.5.</b>
                        
                        lambda表达式
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.6" data-path="home/5.函数及作用域/6.高阶函数.html">
            
                
                    <a href="../../home/5.函数及作用域/6.高阶函数.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.6.</b>
                        
                        高阶函数
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="6" >
            
            <span><b>6.</b> 内置函数及操作</span>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="6.1" data-path="home/6.内置函数及操作/1.字符串相关.html">
            
                
                    <a href="../../home/6.内置函数及操作/1.字符串相关.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.1.</b>
                        
                        字符串相关
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.2" data-path="home/6.内置函数及操作/2.format格式字符串.html">
            
                
                    <a href="../../home/6.内置函数及操作/2.format格式字符串.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.2.</b>
                        
                        format格式字符串
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.3" data-path="home/6.内置函数及操作/3.内建函数.html">
            
                
                    <a href="../../home/6.内置函数及操作/3.内建函数.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.3.</b>
                        
                        内建函数
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.4" data-path="home/6.内置函数及操作/4.列表.html">
            
                
                    <a href="../../home/6.内置函数及操作/4.列表.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.4.</b>
                        
                        列表
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.5" data-path="home/6.内置函数及操作/5.元组.html">
            
                
                    <a href="../../home/6.内置函数及操作/5.元组.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.5.</b>
                        
                        元组
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.6" data-path="home/6.内置函数及操作/6.字典.html">
            
                
                    <a href="../../home/6.内置函数及操作/6.字典.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.6.</b>
                        
                        字典
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.7" data-path="home/6.内置函数及操作/7.集合.html">
            
                
                    <a href="../../home/6.内置函数及操作/7.集合.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.7.</b>
                        
                        集合
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.8" data-path="home/6.内置函数及操作/8.文件操作.html">
            
                
                    <a href="../../home/6.内置函数及操作/8.文件操作.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.8.</b>
                        
                        文件操作
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="7" >
            
            <span><b>7.</b> 常用的模块</span>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="7.1" data-path="home/7.常用模块/1.String模块.html">
            
                
                    <a href="../../home/7.常用模块/1.String模块.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.1.</b>
                        
                        String模块
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.2" data-path="home/7.常用模块/2.math模块.html">
            
                
                    <a href="../../home/7.常用模块/2.math模块.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.2.</b>
                        
                        math模块
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.3" data-path="home/7.常用模块/3.OS模块.html">
            
                
                    <a href="../../home/7.常用模块/3.OS模块.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.3.</b>
                        
                        OS模块
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.4" data-path="home/7.常用模块/4.zipfile模块.html">
            
                
                    <a href="../../home/7.常用模块/4.zipfile模块.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.4.</b>
                        
                        zipfile模块
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.5" data-path="home/7.常用模块/5.tarfile模块.html">
            
                
                    <a href="../../home/7.常用模块/5.tarfile模块.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.5.</b>
                        
                        tarfile模块
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.6" data-path="home/7.常用模块/6.shutil模块.html">
            
                
                    <a href="../../home/7.常用模块/6.shutil模块.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.6.</b>
                        
                        shutil模块
                    </a>
            
            
        </li>
    
        <li class="chapter active" data-level="7.7" data-path="home/7.常用模块/7.时间相关模块.html">
            
                
                    <a href="../../home/7.常用模块/7.时间相关模块.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.7.</b>
                        
                        时间相关模块
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="8" >
            
            <span><b>8.</b> 面向对象</span>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="8.1" data-path="home/8.面向对象/1.类和对象-上.html">
            
                
                    <a href="../../home/8.面向对象/1.类和对象-上.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.1.</b>
                        
                        类和对象-上
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.2" data-path="home/8.面向对象/2.类和对象-下.html">
            
                
                    <a href="../../home/8.面向对象/2.类和对象-下.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.2.</b>
                        
                        类和对象-下
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.3" data-path="home/8.面向对象/3.魔术方法.html">
            
                
                    <a href="../../home/8.面向对象/3.魔术方法.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.3.</b>
                        
                        魔术方法
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.4" data-path="home/8.面向对象/4.装饰器.html">
            
                
                    <a href="../../home/8.面向对象/4.装饰器.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.4.</b>
                        
                        装饰器
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.5" data-path="home/8.面向对象/5.抽象类.html">
            
                
                    <a href="../../home/8.面向对象/5.抽象类.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.5.</b>
                        
                        抽象类
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.6" data-path="home/8.面向对象/6.错误和异常处理.html">
            
                
                    <a href="../../home/8.面向对象/6.错误和异常处理.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.6.</b>
                        
                        错误和异常处理
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.7" data-path="home/8.面向对象/7.模块和包.html">
            
                
                    <a href="../../home/8.面向对象/7.模块和包.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.7.</b>
                        
                        模块和包
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="9" >
            
            <span><b>9.</b> tkinter模块</span>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="9.1" data-path="home/9.tkinter模块/tkinter模块.html">
            
                
                    <a href="../../home/9.tkinter模块/tkinter模块.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>9.1.</b>
                        
                        tkinter模块
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="10" data-path="home/10.网络编程/1.网络编程.html">
            
                
                    <a href="../../home/10.网络编程/1.网络编程.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.</b>
                        
                        网络编程
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="10.1" data-path="home/10.网络编程/2.TCP编程.html">
            
                
                    <a href="../../home/10.网络编程/2.TCP编程.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.1.</b>
                        
                        TCP编程
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="10.2" data-path="home/10.网络编程/3.UDP编程.html">
            
                
                    <a href="../../home/10.网络编程/3.UDP编程.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.2.</b>
                        
                        UDP编程
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="11" data-path="home/11.多任务/多任务原理.html">
            
                
                    <a href="../../home/11.多任务/多任务原理.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>11.</b>
                        
                        多任务
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="11.1" data-path="home/11.多任务/1.多进程实现多任务.html">
            
                
                    <a href="../../home/11.多任务/1.多进程实现多任务.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>11.1.</b>
                        
                        多进程实现多任务
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="11.2" data-path="home/11.多任务/2.多线程实现多任务.html">
            
                
                    <a href="../../home/11.多任务/2.多线程实现多任务.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>11.2.</b>
                        
                        多线程实现多任务
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="11.3" data-path="home/11.多任务/3.协程实现多任务.html">
            
                
                    <a href="../../home/11.多任务/3.协程实现多任务.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>11.3.</b>
                        
                        协程实现多任务
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="12" >
            
            <span><b>12.</b> Python实战项目</span>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="12.1" data-path="home/12.Python实战项目/1.简易计算器.html">
            
                
                    <a href="../../home/12.Python实战项目/1.简易计算器.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>12.1.</b>
                        
                        简易计算器
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="12.2" data-path="home/12.Python实战项目/2.自动售货机.html">
            
                
                    <a href="../../home/12.Python实战项目/2.自动售货机.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>12.2.</b>
                        
                        自动售货机
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="12.3" data-path="home/12.Python实战项目/3.银行项目.html">
            
                
                    <a href="../../home/12.Python实战项目/3.银行项目.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>12.3.</b>
                        
                        银行项目
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="12.4" data-path="home/12.Python实战项目/4.简单的登录注册.html">
            
                
                    <a href="../../home/12.Python实战项目/4.简单的登录注册.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>12.4.</b>
                        
                        简单的登录注册
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="12.5" data-path="home/12.Python实战项目/5.双色球.html">
            
                
                    <a href="../../home/12.Python实战项目/5.双色球.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>12.5.</b>
                        
                        双色球
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="12.6" data-path="home/12.Python实战项目/6.python垃圾回收机制.html">
            
                
                    <a href="../../home/12.Python实战项目/6.python垃圾回收机制.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>12.6.</b>
                        
                        python垃圾回收机制
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="12.7" data-path="home/12.Python实战项目/7.turtle画国旗.html">
            
                
                    <a href="../../home/12.Python实战项目/7.turtle画国旗.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>12.7.</b>
                        
                        turtle画国旗
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="12.8" data-path="home/12.Python实战项目/8.turtle画小猪佩奇.html">
            
                
                    <a href="../../home/12.Python实战项目/8.turtle画小猪佩奇.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>12.8.</b>
                        
                        turtle画小猪佩奇
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="12.9" data-path="home/12.Python实战项目/9.turtle画个表.html">
            
                
                    <a href="../../home/12.Python实战项目/9.turtle画个表.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>12.9.</b>
                        
                        turtle画个表
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    


            
            <li class="divider"></li>
            <li>
                <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                    Published with GitBook
                </a>
            </li>
            
        </ul>
    </nav>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header" role="navigation">
    <!-- Actions Left -->
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../../" >MXY 1.0版Python整理</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1" role="main">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h1 id="&#x65F6;&#x95F4;&#x65E5;&#x671F;&#x76F8;&#x5173;&#x7684;&#x6A21;&#x5757;">&#x65F6;&#x95F4;&#x65E5;&#x671F;&#x76F8;&#x5173;&#x7684;&#x6A21;&#x5757;</h1>
<hr>
<ul>
<li><strong>time&#x3000;&#x3000;&#x3000;&#x65F6;&#x95F4;&#x6A21;&#x5757;</strong></li>
<li><strong>datetime&#x3000;&#x65E5;&#x671F;&#x65F6;&#x95F4;&#x6A21;&#x5757;</strong></li>
<li><strong>calendar&#x3000;&#x65E5;&#x5386;&#x6A21;&#x5757;</strong></li>
</ul>
<hr>
<h2 id="time&#x6A21;&#x5757;">time&#x6A21;&#x5757;</h2>
<blockquote>
<p>&#x5148;&#x5BFC;&#x5165;&#x65F6;&#x95F4;&#x6A21;&#x5757;</p>
<p>import time</p>
</blockquote>
<hr>
<ul>
<li><h3 id="&#x65F6;&#x95F4;&#x6233;">&#x65F6;&#x95F4;&#x6233;</h3>
<pre><code class="lang-py">  &#x65F6;&#x95F4;&#x6233;&#x662F;&#x4E00;&#x79CD;&#x7528;&#x4E8E;&#x8868;&#x793A;&#x65F6;&#x95F4;&#x7684;&#x65B9;&#x5F0F;&#x3002;&#x4ECE;<span class="hljs-number">1970</span>&#x5E74;<span class="hljs-number">1</span>&#x6708;<span class="hljs-number">1</span>&#x65E5;<span class="hljs-number">0</span>&#x65F6;<span class="hljs-number">0</span>&#x5206;<span class="hljs-number">0</span>&#x79D2;<span class="hljs-number">0</span>&#x6BEB;&#x79D2;&#x5F00;&#x59CB;&#x5230;&#x6307;&#x5B9A;&#x65F6;&#x95F4;&#x7684;&#x79D2;&#x6570;&#x3002;&#x4E16;&#x95F4;&#x6233;&#x4E5F;&#x53EB;&#x505A;unix&#x65F6;&#x95F4;&#x6233;&#xFF0C;<span class="hljs-number">1970</span>&#x5E74;<span class="hljs-number">1</span>&#x6708;<span class="hljs-number">1</span>&#x65E5;&#x6210;&#x4E3A;unix&#x5143;&#x5E74;&#x3002;
  &#x4F5C;&#x7528;:&#x662F;&#x4E3A;&#x4E86;&#x65B9;&#x4FBF;&#x65F6;&#x95F4;&#x7684;&#x7EDF;&#x4E00;&#x8FD0;&#x7B97;&#x3002;
  <span class="hljs-number">1.</span>&#x4ECE;<span class="hljs-number">1970</span>&#x5E74;<span class="hljs-number">1</span>&#x6708;<span class="hljs-number">1</span>&#x65E5;&#x5F00;&#x59CB;&#x8BA1;&#x7B97;&#x3002;
  <span class="hljs-number">2.</span>&#x80FD;&#x591F;&#x4F7F;&#x7528;&#x5230;<span class="hljs-number">2038</span>&#x5E74;&#x7684;&#x67D0;&#x4E00;&#x5929;
  <span class="hljs-number">3.</span>&#x5982;&#x679C;&#x4F7F;&#x7528;&#x592A;&#x8FDC;&#x7684;&#x672A;&#x6765;&#x6216;&#x8005;<span class="hljs-number">1970</span>&#x5E74;&#x4EE5;&#x524D;&#x7684;&#x65F6;&#x95F4;&#x53EF;&#x80FD;&#x51FA;&#x73B0;&#x5F02;&#x5E38;
</code></pre>
</li>
<li><h3 id="utc&#x65F6;&#x95F4;">UTC&#x65F6;&#x95F4;</h3>
<pre><code class="lang-py">  UTC&#x65F6;&#x95F4;&#x53C8;&#x79F0;&#x4E3A;&#x4E16;&#x754C;&#x534F;&#x8C03;&#x65F6;&#x95F4;,&#x7279;&#x6307;&#x683C;&#x6797;&#x5C3C;&#x6CBB;&#x5929;&#x6587;&#x53F0;&#x6240;&#x5728;&#x7684;&#x4F4D;&#x7F6E;&#x7684;&#x65F6;&#x95F4;,&#x4E5F;&#x53EB;&#x683C;&#x6797;&#x5C3C;&#x6CBB;&#x65F6;&#x95F4;.
  &#x4E2D;&#x56FD;&#x7684;&#x65F6;&#x533A;&#x662F;&#x4E1C;&#x516B;&#x533A;,&#x6BD4;&#x4E16;&#x754C;&#x534F;&#x8C03;&#x65F6;&#x95F4;&#x5FEB;&#x4E86;<span class="hljs-number">8</span>&#x4E2A;&#x5C0F;&#x65F6;
</code></pre>
</li>
<li><h3 id="&#x590F;&#x4EE4;&#x65F6;">&#x590F;&#x4EE4;&#x65F6;</h3>
<pre><code class="lang-py">  &#x590F;&#x4EE4;&#x65F6;&#x5C31;&#x662F;&#x901A;&#x8FC7;&#x5728;&#x590F;&#x5B63;&#x5C06;&#x65F6;&#x95F4;&#x8C03;&#x5FEB;&#x4E00;&#x5C0F;&#x65F6;&#xFF0C;&#x6765;&#x63D0;&#x9192;&#x5927;&#x5BB6;&#x65E9;&#x7761;&#x65E9;&#x8D77;&#x8EAB;&#x4F53;&#x597D;&#xFF0C;&#x8282;&#x7701;&#x8721;&#x70DB;&#xFF01;
  &#x6BCF;&#x5929;&#x7684;&#x65F6;&#x949F;&#x53D8;&#x6210;&#x4E86;<span class="hljs-number">25</span>&#x4E2A;&#x5C0F;&#x65F6;&#xFF0C;&#x6CE8;&#x610F;&#x672C;&#x8D28;&#x8FD8;&#x662F;<span class="hljs-number">24</span>&#x4E2A;&#x5C0F;&#x65F6;
</code></pre>
</li>
<li><h3 id="&#x65F6;&#x95F4;&#x5143;&#x7EC4;structtime">&#x65F6;&#x95F4;&#x5143;&#x7EC4;struct_time</h3>
<pre><code class="lang-py">  &#x65F6;&#x95F4;&#x5143;&#x7EC4;&#x5C31;&#x662F;&#x4E00;&#x4E2A;&#x7528;&#x4E8E;&#x8868;&#x793A;&#x65F6;&#x95F4;&#x683C;&#x5F0F;&#x7684;&#x5143;&#x7EC4;&#x6570;&#x636E;&#x800C;&#x5DF2;&#xFF0C;&#x4ED6;&#x662F;time&#x6A21;&#x5757;&#x64CD;&#x4F5C;&#x65F6;&#x95F4;&#x7684;&#x4E3B;&#x8981;&#x65B9;&#x5F0F;&#x3002;

  (tm_year=<span class="hljs-number">2017</span>, tm_mon=<span class="hljs-number">7</span>, tm_mday=<span class="hljs-number">4</span>, tm_hour=<span class="hljs-number">9</span>, tm_min=<span class="hljs-number">4</span>, tm_sec=<span class="hljs-number">21</span>, tm_wday=<span class="hljs-number">1</span>, tm_yday=<span class="hljs-number">185</span>, tm_isdst=<span class="hljs-number">0</span>)
  &#x683C;&#x5F0F;:&#xFF08;&#x5E74;&#xFF0C;&#x6708;&#xFF0C;&#x65E5;&#xFF0C;&#x65F6;&#xFF0C;&#x5206;&#xFF0C;&#x79D2;&#xFF0C;&#x5468;&#x51E0;&#xFF0C;&#x4E00;&#x5E74;&#x4E2D;&#x7684;&#x7B2C;&#x51E0;&#x5929;&#xFF0C;&#x662F;&#x5426;&#x662F;&#x590F;&#x4EE4;&#x65F6;&#xFF09;

  &#x7D22;&#x5F15;        &#x540D;&#x79F0;          &#x5185;&#x5BB9;           &#x53D6;&#x503C;
  <span class="hljs-number">0</span>        tm_year        &#x5E74;           <span class="hljs-number">4</span>&#x4F4D;&#x6570;&#x5E74;&#x4EFD;   <span class="hljs-number">2017</span>
  <span class="hljs-number">1</span>        tm_month       &#x6708;           <span class="hljs-number">1</span>&#xFF5E;<span class="hljs-number">12</span>
  <span class="hljs-number">2</span>        tm_day         &#x65E5;           <span class="hljs-number">1</span>&#xFF5E;<span class="hljs-number">31</span>
  <span class="hljs-number">3</span>        tm_hour        &#x65F6;           <span class="hljs-number">0</span>&#xFF5E;<span class="hljs-number">23</span> 
  <span class="hljs-number">4</span>        tm_min         &#x5206;           <span class="hljs-number">0</span>&#xFF5E;<span class="hljs-number">59</span> 
  <span class="hljs-number">5</span>        tm_sec         &#x79D2;           <span class="hljs-number">0</span>&#xFF5E;<span class="hljs-number">61</span>  <span class="hljs-number">60</span>&#x95F0;&#x79D2;&#xFF0C;<span class="hljs-number">61</span>&#x662F;&#x5386;&#x53F2;&#x4FDD;&#x7559;
  <span class="hljs-number">6</span>        tm_wday        &#x5468;&#x51E0;          <span class="hljs-number">0</span>&#xFF5E;<span class="hljs-number">6</span>  &#x5468;&#x4E00;&#xFF5E;&#x5468;&#x5929;
  <span class="hljs-number">7</span>        tm_yday        &#x4E00;&#x5E74;&#x4E2D;&#x7684;&#x7B2C;&#x51E0;&#x5929;  <span class="hljs-number">1</span>&#xFF5E;<span class="hljs-number">366</span>
  <span class="hljs-number">8</span>        tm_isdst       &#x590F;&#x4EE4;&#x65F6;         <span class="hljs-number">0</span> &#x662F;  &#x5176;&#x4ED6;&#x4E0D;&#x662F;
</code></pre>
</li>
</ul>
<hr>
<ul>
<li><h3 id="&#x65F6;&#x95F4;&#x6A21;&#x5757;&#x7684;&#x503C;">&#x65F6;&#x95F4;&#x6A21;&#x5757;&#x7684;&#x503C;</h3>
<ul>
<li><h4 id="timezone">timezone</h4>
<pre><code class="lang-py">  &#x529F;&#x80FD;: &#x83B7;&#x53D6;UTC&#x548C;&#x5F53;&#x524D;&#x65F6;&#x533A;&#x65F6;&#x95F4;&#x6233;&#x7684;&#x5DEE;&#x503C; (UTC&#x65F6;&#x95F4;&#x6233; - &#x5F53;&#x524D;&#x65F6;&#x533A;&#x65F6;&#x95F4;&#x6233;)

  <span class="hljs-keyword">import</span> time 
  print(time.timezone)
</code></pre>
</li>
<li><h4 id="altzone">altzone</h4>
<pre><code class="lang-py">  &#x529F;&#x80FD;: &#x5728;&#x590F;&#x4EE4;&#x65F6;&#x7684;&#x60C5;&#x51B5;&#x4E0B;,&#x83B7;&#x53D6;UTC&#x65F6;&#x95F4;&#x548C;&#x5F53;&#x524D;&#x65F6;&#x533A;&#x7684;&#x5DEE;&#x503C;

  <span class="hljs-keyword">import</span> time 
  print(time.altzone)
</code></pre>
</li>
<li><h4 id="daylight">daylight</h4>
<pre><code class="lang-py">  &#x529F;&#x80FD;: &#x68C0;&#x6D4B;&#x662F;&#x5426;&#x662F;&#x590F;&#x4EE4;&#x65F6;,<span class="hljs-number">0</span> &#x5C31;&#x662F; &#x590F;&#x4EE4;&#x65F6;  &#x975E;&#x96F6;&#x4E0D;&#x662F;&#x590F;&#x4EE4;&#x65F6;

  <span class="hljs-keyword">import</span> time 
  print(time.daylight)
</code></pre>
</li>
</ul>
</li>
<li><h3 id="&#x65F6;&#x95F4;&#x6A21;&#x5757;&#x7684;&#x51FD;&#x6570;">&#x65F6;&#x95F4;&#x6A21;&#x5757;&#x7684;&#x51FD;&#x6570;</h3>
<ul>
<li><h4 id="asctime">asctime()</h4>
<pre><code class="lang-py">  &#x529F;&#x80FD;&#xFF1A;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x6B63;&#x5E38;&#x7684;&#x53EF;&#x8BFB;&#x7684;&#x65F6;&#x95F4;&#x5B57;&#x7B26;&#x4E32;
  &#x683C;&#x5F0F;&#xFF1A;time.asctime(&#x65F6;&#x95F4;&#x5143;&#x7EC4;)
  &#x8FD4;&#x56DE;&#x503C;&#xFF1A;&#x65F6;&#x95F4;&#x5B57;&#x7B26;&#x4E32;

  <span class="hljs-keyword">import</span> time 
  result = time.asctime((<span class="hljs-number">1992</span>,<span class="hljs-number">2</span>,<span class="hljs-number">1</span>,<span class="hljs-number">21</span>,<span class="hljs-number">33</span>,<span class="hljs-number">44</span>,<span class="hljs-number">0</span>,<span class="hljs-number">0</span>,<span class="hljs-number">0</span>))
  print(result)
</code></pre>
</li>
<li><h4 id="localtime">localtime()</h4>
<pre><code class="lang-py">  &#x529F;&#x80FD;&#xFF1A;&#x83B7;&#x53D6;&#x5F53;&#x524D;&#x65F6;&#x95F4;&#x5143;&#x7EC4;
  &#x683C;&#x5F0F;<span class="hljs-number">1</span>&#xFF1A;time.localtime()
      &#x8FD4;&#x56DE;&#x503C;&#xFF1A;&#x672C;&#x5730;&#x65F6;&#x95F4;&#x5143;&#x7EC4;

  &#x683C;&#x5F0F;<span class="hljs-number">2</span>&#xFF1A;time.localtime(&#x65F6;&#x95F4;&#x6233;)
      &#x8FD4;&#x56DE;&#x503C;:&#x6307;&#x5B9A;&#x65F6;&#x95F4;&#x6233;&#x7684;&#x672C;&#x5730;&#x65F6;&#x95F4;&#x5143;&#x7EC4;

  <span class="hljs-keyword">import</span> time 
  result = time.localtime()
  print(result)

  result = time.localtime(<span class="hljs-number">1231424</span>)
  print(result)
</code></pre>
</li>
<li><h4 id="gmtime">gmtime()</h4>
<pre><code class="lang-py">  &#x529F;&#x80FD;&#xFF1A;&#x83B7;&#x53D6;&#x5F53;&#x524D;UTC&#x65F6;&#x95F4;&#x5143;&#x7EC4;
  &#x683C;&#x5F0F;<span class="hljs-number">1</span>&#xFF1A;time.gmtime()
      &#x8FD4;&#x56DE;&#x503C;&#xFF1A;&#x5F53;&#x524D;UTC&#x65F6;&#x95F4;&#x5143;&#x7EC4;

  &#x683C;&#x5F0F;<span class="hljs-number">2</span>&#xFF1A;time.gmtime(&#x65F6;&#x95F4;&#x6233;)
      &#x8FD4;&#x56DE;&#x503C;&#xFF1A;&#x6307;&#x5B9A;&#x65F6;&#x95F4;&#x6233;&#x7684;UTC&#x65F6;&#x95F4;&#x5143;&#x7EC4;

  <span class="hljs-keyword">import</span> time 
  result = time.gmtime()
  print(result)

  result = time.gmtime(<span class="hljs-number">135454426</span>)
  print(result)
</code></pre>
</li>
<li><h4 id="ctime">ctime()</h4>
<pre><code class="lang-py">  &#x529F;&#x80FD;&#xFF1A;&#x83B7;&#x53D6;&#x672C;&#x5730;&#x65F6;&#x95F4;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#x683C;&#x5F0F;
  &#x683C;&#x5F0F;<span class="hljs-number">1</span>&#xFF1A; time.ctime()
      &#x8FD4;&#x56DE;&#x503C;&#xFF1A;&#x65F6;&#x95F4;&#x683C;&#x5F0F;&#x5B57;&#x7B26;&#x4E32; &#x76F8;&#x5F53;&#x4E8E; asctime(localtime())

  &#x683C;&#x5F0F;<span class="hljs-number">2</span>&#xFF1A; time.ctime(&#x65F6;&#x95F4;&#x6233;)
      &#x8FD4;&#x56DE;&#x503C;&#xFF1A;&#x65F6;&#x95F4;&#x683C;&#x5F0F;&#x5B57;&#x7B26;&#x4E32; &#x76F8;&#x5F53;&#x4E8E;asctime(localtime&#xFF08;&#x65F6;&#x95F4;&#x6233;&#xFF09;)

  <span class="hljs-keyword">import</span> time 
  result = time.ctime()
  print(result)
</code></pre>
</li>
<li><h4 id="mktime">mktime()</h4>
<pre><code class="lang-py">  &#x529F;&#x80FD;&#xFF1A;&#x4F7F;&#x7528;&#x65F6;&#x95F4;&#x5143;&#x7EC4;&#x5236;&#x4F5C;&#x65F6;&#x95F4;&#x6233;
  &#x683C;&#x5F0F;&#xFF1A;time.mktime(&#x65F6;&#x95F4;&#x5143;&#x7EC4;)
  &#x8FD4;&#x56DE;&#x503C;: &#x65F6;&#x95F4;&#x6233;
  &#x6CE8;&#x610F;&#xFF1A;&#x6309;&#x7167;&#x672C;&#x5730;&#x65F6;&#x95F4;&#x6765;&#x8FDB;&#x884C;&#x8BA1;&#x7B97;&#xFF0C;&#x5982;&#x679C;&#x60F3;&#x6309;&#x7167;UTC&#x65F6;&#x95F4;&#x8BA1;&#x7B97;&#xFF0C;&#x5219;&#x662F;calendar.timegm()

  <span class="hljs-keyword">import</span> time 
  result = time.mktime((<span class="hljs-number">1992</span>,<span class="hljs-number">2</span>,<span class="hljs-number">1</span>,<span class="hljs-number">23</span>,<span class="hljs-number">45</span>,<span class="hljs-number">22</span>,<span class="hljs-number">0</span>,<span class="hljs-number">0</span>,<span class="hljs-number">0</span>))
  print(result)
</code></pre>
</li>
<li><h4 id="clock">clock()</h4>
<pre><code class="lang-py">  &#x529F;&#x80FD;&#xFF1A;&#x83B7;&#x53D6;CPU&#x65F6;&#x95F4;&#xFF0C;&#x7528;&#x4E8E;&#x8BA1;&#x7B97;&#x4EE3;&#x7801;&#x6267;&#x884C;&#x65F6;&#x95F4;
  &#x683C;&#x5F0F;&#xFF1A;time.clock()
  &#x8FD4;&#x56DE;&#x503C;&#xFF1A;&#x6D6E;&#x70B9;&#x6570;&#x65F6;&#x95F4;&#x6233;
  &#x4E3B;&#x8981;&#x7528;&#x4E8E;&#x8BA1;&#x7B97;&#x7A0B;&#x5E8F;&#x6267;&#x884C;&#x65F6;&#x95F4;&#xFF0C;&#x5F00;&#x59CB;&#x83B7;&#x53D6;&#x4E00;&#x6B21;&#xFF0C;&#x7A0B;&#x5E8F;&#x6267;&#x884C;&#x5B8C;&#x6BD5;&#x5728;&#x83B7;&#x53D6;&#x4E00;&#x6B21;&#xFF0C;&#x76F8;&#x51CF;&#x83B7;&#x5F97;&#x6267;&#x884C;&#x603B;&#x65F6;&#x95F4;

  <span class="hljs-keyword">import</span> time 

  starttime = time.clock()

  lists = [i *  <span class="hljs-number">2</span> <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> range(<span class="hljs-number">1</span>,<span class="hljs-number">10000</span>)]

  endtime = time.clock()

  ptime = endtime - starttime
  print(ptime)
</code></pre>
</li>
<li><h4 id="perfcounter">perf_counter()</h4>
<pre><code class="lang-py">  &#x529F;&#x80FD;&#xFF1A;&#x83B7;&#x53D6;CPU&#x65F6;&#x95F4;&#x7528;&#x4E8E;&#x8BA1;&#x7B97;&#x65F6;&#x95F4;&#x5DEE;
  &#x683C;&#x5F0F;&#xFF1A;time.perf_counter()
  &#x8FD4;&#x56DE;&#x503C;&#xFF1A;&#x6D6E;&#x70B9;&#x6570;&#x65F6;&#x95F4;&#x6233;
  &#x4E3B;&#x8981;&#x7528;&#x4E8E;&#x8BA1;&#x7B97;&#x7A0B;&#x5E8F;&#x6267;&#x884C;&#x65F6;&#x95F4;&#xFF0C;&#x5F00;&#x59CB;&#x83B7;&#x53D6;&#x4E00;&#x6B21;&#xFF0C;&#x7A0B;&#x5E8F;&#x6267;&#x884C;&#x5B8C;&#x6BD5;&#x5728;&#x83B7;&#x53D6;&#x4E00;&#x6B21;&#xFF0C;&#x76F8;&#x51CF;&#x83B7;&#x5F97;&#x6267;&#x884C;&#x603B;&#x65F6;&#x95F4;&#xFF0C;&#x4EC5;py3<span class="hljs-number">.3</span>&#x4EE5;&#x4E0A;

  <span class="hljs-keyword">import</span> time 

  starttime = time.perf_counter()

  time.sleep(<span class="hljs-number">2</span>)

  endtime = time.perf_counter()

  ptime = endtime - starttime
  print(ptime)
</code></pre>
</li>
<li><h4 id="sleep">sleep()</h4>
<pre><code class="lang-py">  &#x529F;&#x80FD;&#xFF1A;&#x7A0B;&#x5E8F;&#x7761;&#x7720;&#xFF0C;&#x4F7F;&#x5F97;&#x7A0B;&#x5E8F;&#x5728;&#x6B64;&#x5904;&#x7B49;&#x5F85;&#x6307;&#x5B9A;&#x7684;&#x65F6;&#x95F4;
  &#x683C;&#x5F0F;&#xFF1A;time.sleep(&#x65F6;&#x95F4;&#x79D2;&#x6570;)
  &#x8FD4;&#x56DE;&#x503C;&#xFF1A;&#x65E0;

  <span class="hljs-keyword">import</span> time

  time.sleep(<span class="hljs-number">15</span>)

  print(<span class="hljs-string">&apos;&#x6709;&#x5B8C;&#x6CA1;&#x5B8C;&#x4E86;&#x6D4B;&#x8BD5;&#x9700;&#x8981;15s&#x4E48;!?&apos;</span>)
</code></pre>
</li>
<li><h4 id="strftime">strftime()</h4>
<pre><code class="lang-py">  &#x529F;&#x80FD;&#xFF1A;&#x683C;&#x5F0F;&#x5316;&#x8F93;&#x51FA;&#x65F6;&#x95F4;&#x5B57;&#x7B26;&#x4E32;&#xFF08;str foramt time&#xFF09;
  &#x683C;&#x5F0F;&#xFF1A;time.strftime(<span class="hljs-string">&apos;&#x5B57;&#x7B26;&#x4E32;&#x683C;&#x5F0F;&apos;</span>[,&#x65F6;&#x95F4;&#x5143;&#x7EC4;])
  &#x8FD4;&#x56DE;&#x503C;&#xFF1A;&#x683C;&#x5F0F;&#x5316;&#x4E4B;&#x540E;&#x7684;&#x54E6;&#x5B57;&#x7B26;&#x4E32;

  &#x683C;&#x5F0F;    &#x542B;&#x4E49;        &#x5907;&#x6CE8;
  %a    &#x672C;&#x5730;&#xFF08;locale&#xFF09;&#x7B80;&#x5316;&#x661F;&#x671F;&#x540D;&#x79F0;
  %A    &#x672C;&#x5730;&#x5B8C;&#x6574;&#x661F;&#x671F;&#x540D;&#x79F0;
  %b    &#x672C;&#x5730;&#x7B80;&#x5316;&#x6708;&#x4EFD;&#x540D;&#x79F0;
  %B    &#x672C;&#x5730;&#x5B8C;&#x6574;&#x6708;&#x4EFD;&#x540D;&#x79F0;
  %c    &#x672C;&#x5730;&#x76F8;&#x5E94;&#x7684;&#x65E5;&#x671F;&#x548C;&#x65F6;&#x95F4;&#x8868;&#x793A;
  %d    &#x4E00;&#x4E2A;&#x6708;&#x4E2D;&#x7684;&#x7B2C;&#x51E0;&#x5929;&#xFF08;<span class="hljs-number">01</span> - <span class="hljs-number">31</span>&#xFF09;
  %H    &#x4E00;&#x5929;&#x4E2D;&#x7684;&#x7B2C;&#x51E0;&#x4E2A;&#x5C0F;&#x65F6;&#xFF08;<span class="hljs-number">24</span> &#x5C0F;&#x65F6;&#x5236;&#xFF0C;<span class="hljs-number">00</span> - <span class="hljs-number">23</span>&#xFF09;
  %I    &#x4E00;&#x5929;&#x4E2D;&#x7684;&#x7B2C;&#x51E0;&#x4E2A;&#x5C0F;&#x65F6;&#xFF08;<span class="hljs-number">12</span> &#x5C0F;&#x65F6;&#x5236;&#xFF0C;<span class="hljs-number">01</span> - <span class="hljs-number">12</span>&#xFF09;
  %j    &#x4E00;&#x5E74;&#x4E2D;&#x7684;&#x7B2C;&#x51E0;&#x5929;&#xFF08;<span class="hljs-number">001</span> - <span class="hljs-number">366</span>&#xFF09;
  %m    &#x6708;&#x4EFD;&#xFF08;<span class="hljs-number">01</span> - <span class="hljs-number">12</span>&#xFF09;
  %M    &#x5206;&#x949F;&#x6570;&#xFF08;<span class="hljs-number">00</span> - <span class="hljs-number">59</span>&#xFF09;
  %p    &#x672C;&#x5730; am &#x6216;&#x8005; pm &#x7684;&#x76F8;&#x5E94;&#x7B26;    &#x6CE8;<span class="hljs-number">1</span>
  %S    &#x79D2;&#xFF08;<span class="hljs-number">01</span> - <span class="hljs-number">61</span>&#xFF09;    &#x6CE8;<span class="hljs-number">2</span>
  %U    &#x4E00;&#x5E74;&#x4E2D;&#x7684;&#x661F;&#x671F;&#x6570;&#xFF08;<span class="hljs-number">00</span> - <span class="hljs-number">53</span> &#x661F;&#x671F;&#x5929;&#x662F;&#x4E00;&#x4E2A;&#x661F;&#x671F;&#x7684;&#x5F00;&#x59CB;&#xFF09;&#x7B2C;&#x4E00;&#x4E2A;&#x661F;&#x671F;&#x5929;&#x4E4B;&#x524D;&#x7684;&#x6240;&#x6709;&#x5929;&#x6570;&#x90FD;&#x653E;&#x5728;&#x7B2C; <span class="hljs-number">0</span> &#x5468;    &#x6CE8;<span class="hljs-number">3</span>
  %w    &#x4E00;&#x4E2A;&#x661F;&#x671F;&#x4E2D;&#x7684;&#x7B2C;&#x51E0;&#x5929;&#xFF08;<span class="hljs-number">0</span> - <span class="hljs-number">6</span>&#xFF0C;<span class="hljs-number">0</span> &#x662F;&#x661F;&#x671F;&#x5929;&#xFF09;    &#x6CE8;<span class="hljs-number">3</span>
  %W    &#x548C; %U &#x57FA;&#x672C;&#x76F8;&#x540C;&#xFF0C;&#x4E0D;&#x540C;&#x7684;&#x662F; %W &#x4EE5;&#x661F;&#x671F;&#x4E00;&#x4E3A;&#x4E00;&#x4E2A;&#x661F;&#x671F;&#x7684;&#x5F00;&#x59CB;
  %X    &#x672C;&#x5730;&#x76F8;&#x5E94;&#x65F6;&#x95F4;
  %y    &#x53BB;&#x6389;&#x4E16;&#x7EAA;&#x7684;&#x5E74;&#x4EFD;&#xFF08;<span class="hljs-number">00</span> - <span class="hljs-number">99</span>&#xFF09;
  %Y    &#x5B8C;&#x6574;&#x7684;&#x5E74;&#x4EFD;
  %z    &#x7528; +HHMM &#x6216; -HHMM &#x8868;&#x793A;&#x8DDD;&#x79BB;&#x683C;&#x6797;&#x5A01;&#x6CBB;&#x7684;&#x65F6;&#x533A;&#x504F;&#x79FB;&#xFF08;H &#x4EE3;&#x8868;&#x5341;&#x8FDB;&#x5236;&#x7684;&#x5C0F;&#x65F6;&#x6570;&#xFF0C;M &#x4EE3;&#x8868;&#x5341;&#x8FDB;&#x5236;&#x7684;&#x5206;&#x949F;&#x6570;&#xFF09;
  %%    %&#x53F7;&#x672C;&#x8EAB;
</code></pre>
<pre><code class="lang-py">  <span class="hljs-comment"># &#x53D6;&#x5F53;&#x524D;&#x683C;&#x5F0F;&#x5316;&#x65F6;&#x95F4;</span>
  <span class="hljs-keyword">import</span> time

  res = time.strftime(<span class="hljs-string">&quot;%Y-%m-%d %H:%M:%S&quot;</span>, time.localtime())
  print(res)
</code></pre>
</li>
<li><h4 id="strptime">strptime()</h4>
<pre><code class="lang-py">  &#x529F;&#x80FD;&#xFF1A;&#x89E3;&#x6790;&#x65F6;&#x95F4;&#x5B57;&#x7B26;&#x4E32;&#x6210;&#x4E00;&#x4E2A;&#x5143;&#x7EC4;&#xFF0C;strftime&#x7684;&#x9006;&#x5411;&#x64CD;&#x4F5C;&#xFF08;str parse time&#xFF09;
  &#x683C;&#x5F0F;&#xFF1A;time.strptime(<span class="hljs-string">&apos;&#x65F6;&#x95F4;&#x5B57;&#x7B26;&#x4E32;&apos;</span>,<span class="hljs-string">&apos;&#x65F6;&#x95F4;&#x5B57;&#x7B26;&#x4E32;&#x683C;&#x5F0F;&apos;</span>)
  &#x8FD4;&#x56DE;&#x503C;&#xFF1A;&#x65F6;&#x95F4;&#x5143;&#x7EC4;

  <span class="hljs-keyword">import</span> time

  result = time.strptime(<span class="hljs-string">&apos;1992&#x5E74;2&#x6708;1&#x65E5;,0&#x65F6;2&#x5206;3&#x79D2;&apos;</span>,<span class="hljs-string">&apos;%Y&#x5E74;%m&#x6708;%d&#x65E5;,%H&#x65F6;%M&#x5206;%S&#x79D2;&apos;</span>)
  print(result)
</code></pre>
</li>
<li><h4 id="time">time()</h4>
<pre><code class="lang-py">  &#x529F;&#x80FD;: &#x83B7;&#x53D6;&#x672C;&#x5730;&#x7684;&#x65F6;&#x95F4;&#x6233;
  &#x683C;&#x5F0F;: time.time()
  &#x8FD4;&#x56DE;&#x503C;&#xFF1A;&#x65F6;&#x95F4;&#x6233;

  <span class="hljs-keyword">import</span> time

  result = time.strptime(<span class="hljs-string">&apos;1992&#x5E74;2&#x6708;1&#x65E5;,0&#x65F6;2&#x5206;3&#x79D2;&apos;</span>,<span class="hljs-string">&apos;%Y&#x5E74;%m&#x6708;%d&#x65E5;,%H&#x65F6;%M&#x5206;%S&#x79D2;&apos;</span>)
  print(result)
</code></pre>
</li>
</ul>
</li>
<li><h3 id="&#x4E00;&#x5F20;&#x56FE;&#x8BF4;&#x660E;&#x5404;&#x79CD;&#x65F6;&#x95F4;&#x4E4B;&#x95F4;&#x7684;&#x76F8;&#x4E92;&#x8F6C;&#x6362;">&#x4E00;&#x5F20;&#x56FE;&#x8BF4;&#x660E;&#x5404;&#x79CD;&#x65F6;&#x95F4;&#x4E4B;&#x95F4;&#x7684;&#x76F8;&#x4E92;&#x8F6C;&#x6362;</h3>
<p>  <img src="../images/&#x4E00;&#x5F20;&#x56FE;&#x8BF4;&#x660E;&#x5404;&#x79CD;&#x65F6;&#x95F4;&#x4E4B;&#x95F4;&#x7684;&#x76F8;&#x4E92;&#x8F6C;&#x6362;.png" alt=""></p>
<ul>
<li><p>&#x7EC3;&#x4E60;&#x9898;</p>
<pre><code class="lang-py">  <span class="hljs-keyword">import</span> time

  <span class="hljs-comment"># &#x8FD4;&#x56DE;&#x5F53;&#x524D;&#x65F6;&#x95F4;&#x7684;&#x65F6;&#x95F4;&#x6233;&#xFF0C;&#x6D6E;&#x70B9;&#x6570;&#x5F62;&#x5F0F;</span>
  a = time.time()
  <span class="hljs-comment"># print(a)</span>

  <span class="hljs-comment"># &#x5C06;&#x65F6;&#x95F4;&#x6233;&#x8F6C;&#x4E3A;UTC&#x65F6;&#x95F4;&#x5143;&#x7EC4;</span>
  b = time.gmtime(a)
  <span class="hljs-comment"># print(b)</span>

  <span class="hljs-comment"># &#x5C06;&#x65F6;&#x95F4;&#x6233;&#x8F6C;&#x4E3A;&#x672C;&#x5730;&#x65F6;&#x95F4;&#x5143;&#x7EC4;</span>
  c = time.localtime(a)
  print(c)

  <span class="hljs-comment"># &#x5C06;&#x672C;&#x5730;&#x65F6;&#x95F4;&#x5143;&#x7EC4;&#x8F6C;&#x4E3A;&#x65F6;&#x95F4;&#x6233;</span>
  d = time.mktime(c)
  <span class="hljs-comment"># print(d)</span>

  <span class="hljs-comment"># &#x5C06;&#x65F6;&#x95F4;&#x5143;&#x7EC4;&#x8F6C;&#x4E3A;&#x5B57;&#x7B26;&#x4E32;</span>
  e = time.asctime(c)
  print(e)

  <span class="hljs-comment"># &#x5C06;&#x65F6;&#x95F4;&#x6233;&#x8F6C;&#x4E3A;&#x5B57;&#x7B26;&#x4E32;   time.asctime(time.localtime(time.time()))</span>
  f = time.ctime(a)
  <span class="hljs-comment"># print(f)</span>

  <span class="hljs-comment"># &#x5C06;&#x65F6;&#x95F4;&#x5143;&#x7EC4;&#x8F6C;&#x6362;&#x4E3A;&#x7ED9;&#x5B9A;&#x683C;&#x5F0F;&#x7684;&#x5B57;&#x7B26;&#x4E32;</span>
  <span class="hljs-comment"># &#x683C;&#x6797;&#x5C3C;&#x6CBB;&#x65F6;&#x95F4;</span>
  g1 = time.strftime(<span class="hljs-string">&quot;%Y-%m-%d %H:%M:%S&quot;</span>, b)
  <span class="hljs-comment"># &#x5F53;&#x524D;&#x65F6;&#x95F4;</span>
  g2 = time.strftime(<span class="hljs-string">&quot;%Y-%m-%d %X&quot;</span>, c)
  <span class="hljs-comment"># print(g1, type(g1))</span>
  <span class="hljs-comment"># print(g2, type(g2))</span>

  <span class="hljs-comment"># &#x5C06;&#x65F6;&#x95F4;&#x5B57;&#x7B26;&#x4E32;&#x8F6C;&#x4E3A;&#x65F6;&#x95F4;&#x5143;&#x7EC4;</span>
  h = time.strptime(g1, <span class="hljs-string">&quot;%Y-%m-%d %H:%M:%S&quot;</span>)
  <span class="hljs-comment"># print(h)</span>

  k = time.strftime(<span class="hljs-string">&quot;%Y-%m-%d %H:%M:%S&quot;</span>, time.localtime())
  <span class="hljs-comment"># print(k)</span>

  <span class="hljs-comment"># &#x5EF6;&#x8FDF;&#x4E00;&#x4E2A;&#x65F6;&#x95F4;&#xFF0C;&#x6574;&#x578B;&#x6216;&#x8005;&#x6D6E;&#x70B9;&#x578B;&#xFF0C;&#x5355;&#x4F4D;&#x662F;s</span>
  <span class="hljs-comment"># time.sleep(4)</span>

  <span class="hljs-comment"># &#x8FD4;&#x56DE;&#x5F53;&#x524D;&#x7A0B;&#x5E8F;&#x7684;cpu&#x6267;&#x884C;&#x65F6;&#x95F4;</span>
  <span class="hljs-comment"># Unix&#x7CFB;&#x7EDF;&#x8FD4;&#x56DE;&#x5168;&#x90E8;&#x7684;&#x8FD0;&#x884C;&#x65F6;&#x95F4;</span>
  <span class="hljs-comment"># Windows&#x4ECE;&#x7B2C;&#x4E8C;&#x6B21;&#x5F00;&#x59CB;&#xFF0C;&#x90FD;&#x662F;&#x4EE5;&#x7B2C;&#x4E00;&#x6B21;&#x8C03;&#x7528;&#x6B64;&#x51FD;&#x6570;&#x7684;&#x5F00;&#x59CB;&#x65F6;&#x95F4;&#x6233;&#x4F5C;&#x4E3A;&#x8BA1;&#x6570;</span>
  m1 = time.clock()
  <span class="hljs-comment"># print(&quot;%d&quot; % m1)</span>
  <span class="hljs-comment"># time.sleep(2)</span>
  m2 = time.clock()
  <span class="hljs-comment"># print(&quot;%d&quot; % m2)</span>
  <span class="hljs-comment"># time.sleep(2)</span>
  m3 = time.clock()
  <span class="hljs-comment"># print(&quot;%d&quot; % m3)</span>
</code></pre>
</li>
<li><p>&#x4E24;&#x9053;&#x9898;</p>
<pre><code class="lang-py">  <span class="hljs-comment"># -*- coding:utf-8 -*-</span>
  <span class="hljs-keyword">import</span> time
  <span class="hljs-keyword">import</span> datetime

  <span class="hljs-comment"># &#x8F93;&#x5165;&#x5E74;&#x6708;&#x65E5;&#xFF0C;&#x8FD4;&#x56DE;&#x65E5;&#x671F;&#x4E3A;&#x8FD9;&#x4E00;&#x5E74;&#x7684;&#x7B2C;&#x51E0;&#x5929;</span>
  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">get_time</span><span class="hljs-params">(str_time)</span>:</span>
      <span class="hljs-keyword">return</span> time.mktime(time.strptime(str_time, <span class="hljs-string">&apos;%Y-%m-%d&apos;</span>))

  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">count_date</span><span class="hljs-params">(year, month, day)</span>:</span>
      base_str_time = <span class="hljs-string">&apos;%s-1-1&apos;</span> % year
      base_time = get_time(base_str_time)
      str_time = <span class="hljs-string">&apos;%s-%s-%s&apos;</span> % (year, month, day)
      time = get_time(str_time)
      retTime = int((time-base_time)/<span class="hljs-number">3600</span>/<span class="hljs-number">24</span>) + <span class="hljs-number">1</span>
      <span class="hljs-keyword">return</span> retTime

  <span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">&apos;__main__&apos;</span>:
      print(count_date(<span class="hljs-number">1997</span>, <span class="hljs-number">6</span>, <span class="hljs-number">13</span>))
</code></pre>
<pre><code class="lang-py">  <span class="hljs-comment"># -*- coding:utf-8 -*-</span>
  <span class="hljs-keyword">import</span> time
  <span class="hljs-keyword">import</span> datetime

  <span class="hljs-comment"># &#x8F93;&#x5165;&#x67D0;&#x4E00;&#x5E74;&#x7684;&#x5929;&#x6570;&#xFF0C;&#x8FD4;&#x56DE;&#x5E74;&#x6708;&#x65E5;</span>
  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">out_date</span><span class="hljs-params">(year, day)</span>:</span>
      <span class="hljs-comment"># &#x4F7F;&#x7528;datetime</span>
      <span class="hljs-comment"># tmp_days = datetime.datetime(year, 1, 1)</span>
      <span class="hljs-comment"># days = datetime.timedelta(days=day-1)</span>
      <span class="hljs-comment"># retTime = datetime.datetime.strftime(tmp_days+days, &apos;%Y-%m-%d&apos;)</span>
      <span class="hljs-comment"># return retTime</span>

      <span class="hljs-comment"># &#x4F7F;&#x7528;time</span>
      time1 = (day-<span class="hljs-number">1</span>)*<span class="hljs-number">24</span>*<span class="hljs-number">3600</span>
      base_str_time = <span class="hljs-string">&apos;%s-1-1&apos;</span> % year
      base_time = get_time(base_str_time)
      time2 = time1 + base_time
      ret = time.strftime(<span class="hljs-string">&apos;%Y-%m-%d&apos;</span>, time.localtime(time2))
      <span class="hljs-keyword">return</span> ret

  <span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">&apos;__main__&apos;</span>:
      print(out_date(<span class="hljs-number">1997</span>, <span class="hljs-number">164</span>))
</code></pre>
</li>
</ul>
</li>
</ul>
<hr>
<h2 id="datetime&#x6A21;&#x5757;">datetime&#x6A21;&#x5757;</h2>
<blockquote>
<p>&#x4F7F;&#x7528;&#x524D;&#x4E5F;&#x8981;&#x5148;&#x5BFC;&#x5165;</p>
<p>import datetime</p>
</blockquote>
<ul>
<li><h3 id="&#x7B80;&#x5355;&#x4ECB;&#x7ECD;">&#x7B80;&#x5355;&#x4ECB;&#x7ECD;</h3>
<pre><code class="lang-py">  datetime&#x6BD4;time&#x9AD8;&#x7EA7;&#x4E86;&#x4E0D;&#x5C11;&#xFF0C;&#x53EF;&#x4EE5;&#x7406;&#x89E3;&#x4E3A;datetime&#x57FA;&#x4E8E;time&#x8FDB;&#x884C;&#x4E86;&#x5C01;&#x88C5;&#xFF0C;&#x63D0;&#x4F9B;&#x4E86;&#x66F4;&#x4E3A;&#x5B9E;&#x7528;&#x7684;&#x51FD;&#x6570;&#xFF0C;datetime&#x6A21;&#x5757;&#x7684;&#x63A5;&#x53E3;&#x66F4;&#x76F4;&#x89C2;&#xFF0C;&#x66F4;&#x5BB9;&#x6613;&#x8C03;&#x7528;
  &#x6A21;&#x5757;&#x4E2D;&#x7684;&#x7C7B;&#xFF1A;
      datetime    &#x540C;&#x65F6;&#x6709;&#x65F6;&#x95F4;&#x548C;&#x65E5;&#x671F;
      timedelta   &#x4E3B;&#x8981;&#x7528;&#x4E8E;&#x8BA1;&#x7B97;&#x65F6;&#x95F4;&#x7684;&#x8DE8;&#x5EA6;
      tzinfo      &#x65F6;&#x533A;&#x76F8;&#x5173;
      time        &#x53EA;&#x5173;&#x6CE8;&#x65F6;&#x95F4;
      date        &#x53EA;&#x5173;&#x6CE8;&#x65E5;&#x671F;

  <span class="hljs-comment"># &#x8BE6;&#x7EC6;&#x7406;&#x89E3;&#x8BF7;&#x8FDB;&#x5165; https://blog.csdn.net/cmzsteven/article/details/64906245</span>
</code></pre>
</li>
<li><h3 id="&#x83B7;&#x53D6;&#x5F53;&#x524D;&#x65F6;&#x95F4;">&#x83B7;&#x53D6;&#x5F53;&#x524D;&#x65F6;&#x95F4;</h3>
<pre><code class="lang-py">  import datetime

  d1 = datetime.datetime.now()
  print(d1, type(d1))

  2018-10-14 17:28:25.214816 &lt;class &apos;datetime.datetime&apos;&gt;
</code></pre>
</li>
<li><h3 id="&#x83B7;&#x53D6;&#x6307;&#x5B9A;&#x65F6;&#x95F4;">&#x83B7;&#x53D6;&#x6307;&#x5B9A;&#x65F6;&#x95F4;</h3>
<pre><code class="lang-py">  import datetime

  d2 = datetime.datetime(1999, 10, 1, 10, 28, 25, 123456)
  print(d2, type(d2))

  1999-10-01 10:28:25.123456 &lt;class &apos;datetime.datetime&apos;&gt;
</code></pre>
</li>
<li><h3 id="&#x5C06;&#x65F6;&#x95F4;&#x8F6C;&#x4E3A;&#x5B57;&#x7B26;&#x4E32;">&#x5C06;&#x65F6;&#x95F4;&#x8F6C;&#x4E3A;&#x5B57;&#x7B26;&#x4E32;</h3>
<pre><code class="lang-py">  <span class="hljs-keyword">import</span> datetime

  d1 = datetime.datetime.now().strftime(<span class="hljs-string">&quot;%Y-%m-%d %X&quot;</span>)
  print(d1)

  <span class="hljs-number">2018</span>-<span class="hljs-number">10</span>-<span class="hljs-number">14</span> <span class="hljs-number">17</span>:<span class="hljs-number">32</span>:<span class="hljs-number">24</span>
</code></pre>
</li>
</ul>
<ul>
<li><h3 id="&#x5C06;&#x683C;&#x5F0F;&#x5316;&#x5B57;&#x7B26;&#x4E32;&#x8F6C;&#x4E3A;datetime&#x5BF9;&#x8C61;">&#x5C06;&#x683C;&#x5F0F;&#x5316;&#x5B57;&#x7B26;&#x4E32;&#x8F6C;&#x4E3A;datetime&#x5BF9;&#x8C61;</h3>
<pre><code class="lang-py">  import datetime

  # &#x6CE8;&#x610F;&#xFF1A;&#x8F6C;&#x6362;&#x7684;&#x683C;&#x5F0F;&#x8981;&#x4E0E;&#x5B57;&#x7B26;&#x4E32;&#x4E00;&#x81F4;
  d1 = datetime.datetime.strptime(datetime.datetime.now().strftime(&quot;%Y-%m-%d %X&quot;), &quot;%Y-%m-%d %X&quot;)
  print(d1, type(d1))

  2018-10-14 17:36:27 &lt;class &apos;datetime.datetime&apos;&gt;
</code></pre>
</li>
<li><h3 id="&#x8BA1;&#x7B97;&#x5929;&#x6570;&#x5DEE;">&#x8BA1;&#x7B97;&#x5929;&#x6570;&#x5DEE;</h3>
<pre><code class="lang-py">  import datetime

  d1 = datetime.datetime(1999, 10, 1, 10, 28, 25, 123456)
  d2 = datetime.datetime.now()
  d3 = d2 - d1

  print(d3, type(d3))
  # &#x95F4;&#x9694;&#x7684;&#x5929;&#x6570;
  print(d3.days)
  # &#x95F4;&#x9694;&#x5929;&#x6570;&#x9664;&#x5916;&#x7684;&#x79D2;&#x6570;
  print(d3.seconds)

  6953 days, 7:09:06.144164 &lt;class &apos;datetime.timedelta&apos;&gt;
  6953
  25746
</code></pre>
</li>
</ul>
<hr>
<h2 id="calendar&#x6A21;&#x5757;">calendar&#x6A21;&#x5757;</h2>
<blockquote>
<p>&#x4F7F;&#x7528;&#x524D;&#x4E5F;&#x8981;&#x5148;&#x5BFC;&#x5165;</p>
<p>import datetime</p>
</blockquote>
<ul>
<li><h3 id="&#x65E5;&#x5386;&#x6A21;&#x5757;&#x51FD;&#x6570;">&#x65E5;&#x5386;&#x6A21;&#x5757;&#x51FD;&#x6570;</h3>
<ul>
<li><h4 id="calendarcalendar">calendar.calendar()</h4>
<pre><code class="lang-py">  &#x529F;&#x80FD;&#xFF1A;&#x83B7;&#x53D6;&#x6307;&#x5B9A;&#x5E74;&#x4EFD;&#x7684;&#x65E5;&#x5386;&#x5B57;&#x7B26;&#x4E32;
  &#x683C;&#x5F0F;&#xFF1A;calendar.calendar&#xFF08;&#x5E74;&#x4EFD;, w=<span class="hljs-number">2</span>, l=<span class="hljs-number">1</span>, c=<span class="hljs-number">6</span>, m=<span class="hljs-number">3</span>&#xFF09;
  &#x8FD4;&#x56DE;&#x503C;&#xFF1A;&#x5B57;&#x7B26;&#x4E32;
      w&#x8868;&#x793A; <span class="hljs-number">2</span>&#x4E2A;&#x65E5;&#x671F;&#x4E4B;&#x95F4;&#x7684;&#x95F4;&#x9694;&#x5B57;&#x7B26;&#x957F;&#x5EA6;
      l&#x8868;&#x793A; &#x4E00;&#x4E2A;&#x5468;&#x5360;&#x7528;&#x51E0;&#x4E2A;&#x884C;&#x9AD8;&#x5EA6;
      c&#x8868;&#x793A;<span class="hljs-number">2</span>&#x4E2A;&#x6708;&#x4EFD;&#x4E4B;&#x95F4;&#x7684;&#x7A7A;&#x767D;&#x95F4;&#x9694;
      m&#x8868;&#x793A;&#x4E00;&#x884C;&#x663E;&#x793A;&#x51E0;&#x4E2A;&#x6708;

  <span class="hljs-keyword">import</span> calendar
  result = calendar.calendar(<span class="hljs-number">2017</span>)
  print(result)
</code></pre>
</li>
<li><h4 id="calendarmonth">calendar.month()</h4>
<pre><code class="lang-py">  &#x529F;&#x80FD;&#xFF1A;&#x83B7;&#x53D6;&#x6307;&#x5B9A;&#x5E74;&#x6708;&#x7684;&#x65E5;&#x5386;&#x5B57;&#x7B26;&#x4E32;
  &#x683C;&#x5F0F;&#xFF1A;calendar.month(&#x5E74;&#xFF0C;&#x6708;&#xFF0C;w=<span class="hljs-number">2</span>&#xFF0C;l=<span class="hljs-number">1</span>)
  &#x8FD4;&#x56DE;&#x503C;&#xFF1A;&#x5B57;&#x7B26;&#x4E32;A

  <span class="hljs-keyword">import</span> calendar
  result = calendar.month(<span class="hljs-number">2017</span>, <span class="hljs-number">10</span>)
  print(result)
</code></pre>
</li>
<li><h4 id="calendarmonthcalendar">calendar.monthcalendar()</h4>
<pre><code class="lang-py">  &#x529F;&#x80FD;&#xFF1A;&#x83B7;&#x53D6;&#x4E00;&#x4E2A;&#x5E74;&#x6708;&#x7684;&#x77E9;&#x9635;&#x5217;&#x8868;
  &#x683C;&#x5F0F;&#xFF1A;calendar.monthcalendar(&#x5E74;, &#x6708;)
  &#x8FD4;&#x56DE;&#x503C;&#xFF1A;&#x4E8C;&#x7EA7;&#x5217;&#x8868;
  [
      [<span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">1</span>, <span class="hljs-number">2</span>],
      [<span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>, <span class="hljs-number">6</span>, <span class="hljs-number">7</span>, <span class="hljs-number">8</span>, <span class="hljs-number">9</span>],
      [<span class="hljs-number">10</span>, <span class="hljs-number">11</span>, <span class="hljs-number">12</span>, <span class="hljs-number">13</span>, <span class="hljs-number">14</span>, <span class="hljs-number">15</span>, <span class="hljs-number">16</span>],
      [<span class="hljs-number">17</span>, <span class="hljs-number">18</span>, <span class="hljs-number">19</span>, <span class="hljs-number">20</span>, <span class="hljs-number">21</span>, <span class="hljs-number">22</span>, <span class="hljs-number">23</span>],
      [<span class="hljs-number">24</span>, <span class="hljs-number">25</span>, <span class="hljs-number">26</span>, <span class="hljs-number">27</span>, <span class="hljs-number">28</span>, <span class="hljs-number">29</span>, <span class="hljs-number">30</span>],
      [<span class="hljs-number">31</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>]
  ]
  &#x7ED3;&#x679C;&#x4E2D;<span class="hljs-number">0</span>&#x8868;&#x793A;&#x4E0D;&#x662F;&#x8BE5;&#x6708;&#x7684;&#x6570;&#x503C;&#xFF0C;<span class="hljs-number">1</span>-<span class="hljs-number">31</span>&#x624D;&#x662F;&#x5F53;&#x6708;&#x4FE1;&#x606F;

  <span class="hljs-keyword">import</span> calendar
  result = calendar.monthcalendar(<span class="hljs-number">2017</span>, <span class="hljs-number">10</span>)
  print(result)
</code></pre>
</li>
<li><h4 id="calendarmonthrange">calendar.monthrange()</h4>
<pre><code class="lang-py">  &#x529F;&#x80FD;&#xFF1A;&#x83B7;&#x53D6;&#x4E00;&#x4E2A;&#x6708;&#x7684;&#x5468;&#x51E0;&#x5F00;&#x59CB;&#x53CA;&#x5F53;&#x6708;&#x5929;&#x6570;
  &#x683C;&#x5F0F;&#xFF1A;calendar.monthrange(&#x5E74;&#xFF0C;&#x6708;)
  &#x8FD4;&#x56DE;&#x503C;&#xFF1A;&#x5143;&#x7EC4;(&#x5468;&#x51E0;&#xFF0C;&#x5929;&#x6570;)
  &#x6CE8;&#x610F;&#xFF1A;<span class="hljs-number">0</span>-<span class="hljs-number">6</span>&#x8868;&#x793A;&#x5468;&#x4E00;&#x5230;&#x5468;&#x5929;

  <span class="hljs-keyword">import</span> calendar
  result = calendar.monthrange(<span class="hljs-number">2017</span>, <span class="hljs-number">10</span>)
  print(result)

  (<span class="hljs-number">6</span>, <span class="hljs-number">31</span>)
</code></pre>
</li>
<li><h4 id="calendarisleap">calendar.isleap()</h4>
<pre><code class="lang-py">  &#x529F;&#x80FD;&#xFF1A;&#x68C0;&#x6D4B;&#x6307;&#x5B9A;&#x5E74;&#x4EFD;&#x662F;&#x4E0D;&#x662F;&#x95F0;&#x5E74;
  &#x683C;&#x5F0F;&#xFF1A;calendar.isleap(&#x5E74;&#x4EFD;)
  &#x8FD4;&#x56DE;&#x503C;&#xFF1A;&#x5E03;&#x5C14;&#x503C;

  <span class="hljs-keyword">import</span> calendar
  result = calendar.isleap(<span class="hljs-number">2017</span>)
  print(result)

  <span class="hljs-keyword">False</span>
</code></pre>
</li>
<li><h4 id="calendarleapdays">calendar.leapdays()</h4>
<pre><code class="lang-py">  &#x529F;&#x80FD;&#xFF1A;&#x68C0;&#x6D4B;&#x6307;&#x5B9A;&#x5E74;&#x4EFD;&#x4E4B;&#x95F4;&#x7684;&#x95F0;&#x5E74;&#x4E2A;&#x6570;
  &#x683C;&#x5F0F;&#xFF1A;calendar.leapdays(&#x5F00;&#x59CB;&#x5E74;&#x4EFD;&#xFF0C;&#x7ED3;&#x675F;&#x5E74;&#x4EFD;)
  &#x8FD4;&#x56DE;&#x503C;&#xFF1A;&#x6574;&#x6570;
  &#x6CE8;&#x610F;&#xFF1A;&#x5305;&#x542B;&#x5F00;&#x59CB;&#x5E74;&#x4EFD;&#x4E0D;&#x5305;&#x542B;&#x7ED3;&#x675F;&#x5E74;&#x4EFD;

  <span class="hljs-keyword">import</span> calendar
  result = calendar.leapdays(<span class="hljs-number">1900</span>, <span class="hljs-number">2011</span>)
  print(result)

  <span class="hljs-number">27</span>
</code></pre>
</li>
<li><h4 id="calendarweekday">calendar.weekday()</h4>
<pre><code class="lang-py">  &#x529F;&#x80FD;&#xFF1A;&#x6839;&#x636E;&#x5E74;&#x6708;&#x65E5;&#x8BA1;&#x7B97;&#x5468;&#x51E0;
  &#x683C;&#x5F0F;&#xFF1A;calendar.weekday(&#x5E74;&#xFF0C;&#x6708;&#xFF0C;&#x65E5;)
  &#x8FD4;&#x56DE;&#x503C;&#xFF1A;&#x6574;&#x578B;  <span class="hljs-number">0</span>-<span class="hljs-number">6</span> &#x8868;&#x793A;&#x5468;&#x4E00;&#x5230;&#x5468;&#x5929;

  <span class="hljs-keyword">import</span> calendar
  result = calendar.weekday(<span class="hljs-number">2017</span>,<span class="hljs-number">10</span>,<span class="hljs-number">13</span>)
  print(result)

  <span class="hljs-number">4</span>
</code></pre>
</li>
<li><h4 id="calendartimegm">calendar.timegm()</h4>
<pre><code class="lang-py">  &#x529F;&#x80FD;&#xFF1A;&#x5C06;&#x65F6;&#x95F4;&#x5143;&#x7EC4;&#x8F6C;&#x5316;&#x4E3A;&#x65F6;&#x95F4;&#x6233;
  &#x683C;&#x5F0F;&#xFF1A;calendar.timegm(&#x65F6;&#x95F4;&#x5143;&#x7EC4;)
  &#x8FD4;&#x56DE;&#x503C;&#xFF1A;&#x65F6;&#x95F4;&#x6233;

  <span class="hljs-keyword">import</span> calendar
  ttp = (<span class="hljs-number">2018</span>,<span class="hljs-number">1</span>,<span class="hljs-number">1</span>,<span class="hljs-number">0</span>,<span class="hljs-number">0</span>,<span class="hljs-number">0</span>,<span class="hljs-number">0</span>,<span class="hljs-number">0</span>,<span class="hljs-number">0</span>)
  result = calendar.timegm(ttp)
  print(result)

  <span class="hljs-number">1514764800</span>
</code></pre>
</li>
</ul>
</li>
</ul>

                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="../../home/7.常用模块/6.shutil模块.html" class="navigation navigation-prev " aria-label="Previous page: shutil模块"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../../home/8.面向对象/1.类和对象-上.html" class="navigation navigation-next " aria-label="Next page: 类和对象-上"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../../gitbook/app.js"></script>

    
    <script src="../../gitbook/plugins/gitbook-plugin-search/lunr.min.js"></script>
    

    
    <script src="../../gitbook/plugins/gitbook-plugin-search/search.js"></script>
    

    
    <script src="../../gitbook/plugins/gitbook-plugin-sharing/buttons.js"></script>
    

    
    <script src="../../gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"highlight":{},"search":{"maxIndexSize":1000000},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2}};
    gitbook.start(config);
});
</script>

        
    </body>
    
</html>
